---
title: "Beck and Katz (2014): Table 2, Column 1 replication"
author: "Jeff Lewis"
date: "11/26/2017"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

I grabbed the archived datafile from https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/27269 .  I then fit the models various ways.  A summary table of rounded coefficients appears at the end.

```{r}
library(tidyverse)
library(haven)
dat <- read_dta("garrett1998.dta")
```

Here column one using LSDV:

```{r}
m1 <- lm(gdp ~ 0 + demand + trade + capmob + oild + per6673 + 
               corp + leftlab + clint + as.factor(country) , data=dat)
summary(m1)
```

Here is usual centering approach:
```{r}
m2 <- lm(gdp ~ 0 + demand + trade + capmob + oild + per6673 + 
               corp + leftlab + clint, 
         data=dat %>% group_by(country) %>% mutate_at(vars(gdp,demand,trade,capmob,
                                     oild,per6673,corp,
                                     leftlab,clint),
                                     function(x) x - mean(x))) 
summary(m2)
```

Here is the center-and-then-construct-the-interaction-approach: 

```{r}
m3 <- lm(gdp ~ 0 + demand + trade + capmob + oild + per6673 + 
               corp + leftlab + leftlab*corp  , 
         data=dat %>% group_by(country) %>% mutate_at(vars(gdp,demand,trade,capmob,
                                     oild,per6673,corp,
                                     leftlab,clint),
                                function(x) x - mean(x))) 
summary(m3)
```

Here the point estimates after applying my best guess as to how the publisher rounded in the published table:
```{r}
res <- apply(cbind(coef(m1)[1:8],coef(m2),coef(m3)),c(1,2),
      function(x) {
        rt <- as.integer(cut(abs(x),c(0,0.01,1,Inf)))
        signif(x,rt)
      })
res <- cbind(res,c(0.007,-0.018,-0.20,-7.86,1.76,
                   0.54,-0.075,0.10))
colnames(res) <- c("LSDV","CenterAll","CenterThenInt","Reported")
res
```